
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';


typedef GestureTapCallback = void Function();
class InputView extends StatefulWidget {

//  final String labelText;
  final String errorText;
  final TextInputType keyboardType;///键盘类型
  final TextEditingController textEditingController;///获取值
  final bool obscureText;///是否隐藏 适用于 输入密码
  final FocusNode focusNode;///焦点
  final ValueChanged<String> onChanged;///
  final TextStyle style;
  final TextStyle labelStyle;
  final TextStyle hintStyle;
  final Color cursorColor;///光标颜色
  final bool readOnly;
  final InputBorder enabledBorder;///默认 时的 边框
  final InputBorder focusedBorder;///选中时的 边框
  final bool enabled;///是否禁用
  final Widget icon;///左边图票 👈
  final Widget suffixIcon;///右边图标 👉
  final GestureTapCallback onTap;
  final String labelText;
  final String hintText;
  final Decoration decoration;
  final EdgeInsetsGeometry contentPadding;///内容边框
  final EdgeInsetsGeometry padding;///边框
  final List<TextInputFormatter> inputFormatters;//输入限制
   InputBorder _borderStyle;
  ///
  InputView({
    Key key,
//    this.labelText,
    this.keyboardType,
    this.textEditingController,
    this.errorText,
    this.focusNode,
    this.onChanged,
    this.obscureText = false,
    this.style,
    this.labelStyle,
    this.hintStyle,
    this.cursorColor,
    this.enabledBorder,
    this.focusedBorder,
    this.readOnly = false,
    this.enabled,
    this.icon,
    this.suffixIcon,
    this.onTap,
    this.hintText,
    this.labelText,
    this.contentPadding,
    this.padding,
    this.inputFormatters,
    this.decoration
  }) : super(key: key)

  {
    _borderStyle = UnderlineInputBorder();
  }

  InputView.outlineInputBorder({
  this.keyboardType,
  this.textEditingController,
  this.errorText,
  this.focusNode,
  this.onChanged,
  this.obscureText = false,
  this.style,
  this.labelStyle,
  this.hintStyle,
  this.cursorColor,
  this.enabledBorder,
  this.focusedBorder,
    this.decoration,
  this.readOnly = false,
  this.enabled,
    this.icon,
    this.suffixIcon,
    this.onTap,
    this.labelText,
    this.hintText,
    this.contentPadding,
    this.padding,
    this.inputFormatters

  }){
    _borderStyle = OutlineInputBorder();
  }

  @override
  _InputViewState createState() => _InputViewState();

}
class _InputViewState extends State<InputView> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: widget.padding ?? const EdgeInsets.fromLTRB(15, 0, 15, 0),
      child: TextField(
        onTap: widget.onTap,
        enabled: widget.enabled,
        obscureText: widget.obscureText,
        controller: widget.textEditingController,
        keyboardType: widget.keyboardType,
        focusNode: widget.focusNode,
        readOnly: widget.readOnly,
        inputFormatters: widget.inputFormatters,
        decoration: InputDecoration(
          icon: widget.icon,
          suffixIcon: widget.suffixIcon,
          hintText: widget.hintText,
          border: widget._borderStyle,
          labelText: widget.labelText,
          contentPadding: widget.contentPadding??EdgeInsets.fromLTRB(10, 0, 0, 0),
          labelStyle: widget.labelStyle,
          hintStyle: widget.hintStyle,
        enabledBorder: widget.enabledBorder,
        focusedBorder: widget.focusedBorder,
          errorText:  widget.errorText,

        ),
       style: widget.style,
       cursorColor: widget.cursorColor,
        onChanged: widget.onChanged,
      ),
    );
  }
}
